<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.servletContext.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.servletContext.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.servletContext.contextPath}/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.servletContext.contextPath}/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">平台管理</a>
        <a href="">${platform}</a>
        <a>
          <cite>版本列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<xblock>
    <button class="layui-btn layui-btn-danger" onClick="deleteMutilItem(this)"><i class="layui-icon"></i>删除</button>
    <button class="layui-btn" onclick="x_admin_show('添加','./toAddList',650,400);"><i class="layui-icon"></i>添加
        <button class="layui-btn" onclick="addItem()"><i class="layui-icon"></i>复制添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：${data.size()}条</span>
</xblock>
<table class="layui-table" lay-filter="test">
    <thead>
    <tr>
        <th>
            <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i>
            </div>
        </th>
        <th>序号</th>
        <th>包名</th>
        <th>平台</th>
        <th>版本号</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${data}" varStatus="index" step="1" var="result">
        <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary"
                     data-id='${result.resultData.data.versionId}'><i class="layui-icon">&#xe605;</i>
                </div>
            </td>
            <td>${index.count}</td>
            <td>${result.resultData.data.packageName}</td>
            <td>${result.resultData.data.appType}</td>
            <td>${result.resultData.data.version}</td>
            <td class="td-manage">
                <a onclick="x_admin_show('查看','./versionSwitch?versionName=${result.versionName}')" href="javascript:;"
                   title="查看">
                    <i class="layui-icon">&#xe601;</i>
                </a>
                <a title="编辑" onclick="x_admin_show('编辑','./versionEdit?versionName=${result.versionName}')"
                   href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a onclick="x_admin_show('修改','./editList?versionName=${result.versionName}',650,400)" title="修改"
                   href="javascript:;">
                    <i class="layui-icon">&#xe631;</i>
                </a>
                <a title="删除"
                   onclick="deleteItem(this,'${result.resultData.data.packageName}','${result.resultData.data.appType}','${result.resultData.data.version}')"
                   href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
    </c:forEach>

    </tbody>
</table>


</div>
<script>
    //单条记录删除
    function deleteItem(obj, packageName, appType, version) {
        console.log($(obj))
        layer.confirm('确认要删除 ' + appType + " / " + version + " 版本吗?", function (index) {
            var key = packageName + "-" + appType + "-" + version;
            $.post("./deleteVersion", {mapKey: key}, function (result) {
                if (result.status) {
                    $(obj).parents("tr").remove();
                    layer.msg(result.message, {icon: 1, time: 1000});
                } else
                    layer.msg(result.message, {icon: 2, time: 1000});
            });
        });

    }

    //删除
    function deleteMutilItem(obj) {
        console.log($(obj))
        var delIds = tableCheck.getData();
        if (delIds.length == 0) {
            layer.msg('请选择要删除的数据！', {icon: 2});
        } else {

            layer.confirm('确认要删除当前选择的数据吗?', function (index) {
                $.post("./deleteByIds", {delIds: ''+delIds}, function (result) {
                    if (result.status) {
                        layer.msg(result.message, {icon: 1, time: 1000});
                        javascript:location.replace(location.href);
                    } else
                        layer.msg(result.message, {icon: 2, time: 1000});
                });
            });
        }

    }

    //复制增加
    function addItem() {
        var versionData = tableCheck.getData();
        if (versionData.length == 0) {
            layer.msg('请选择一行要复制的数据！', {icon: 2});
        } else if (versionData.length == 1) {
            x_admin_show('添加', './copyToAddList?versionId=' + versionData, 650, 400);
        } else if (versionData.length > 1) {
            layer.msg('只能选择一行要复制的数据！', {icon: 2});
        }

    }
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>